Dec 94 Tips
Volume Number: 10
Issue Number: 12
Column Tag: Tips &Tidbits
Related Info: Color Quickdraw
Tips &Tidbits 
By Scott T Boyd, Editor
Note: Source code files accompanying article are located on MacTech CD-ROM orsource code disks.
Send us your tips! We’ll send you money, and developers all over the world
(even in Sweden) will marvel at your insight, your wisdom, or the simple fact that
you’ve got enough extra time to write and send a little bit of e-mail to make their lives
a little bit better.
We pay $25 for every tip we use, and $50 for Tip of the Month. You can take
your award in orders or subscriptions if you prefer. Make sure code compiles, and
send tips by e-mail; editorial@xplain.com is a great address. See page two for our
other addresses.
Tip Of The Month
White-Bordered Black Text Mode
A recent thread on comp.sys.mac.programmer prompted this little code snippet to
work around a glaring omission on QuickDraw text modes. This is actual, tested,
working code to draw a white outline around black characters. The trick is in the use
of CharExtra, a Color QuickDraw routine that’s worth reading about in Inside
Macintosh.
/* 1 */
void
Outline (
short x ,
short y ,
Ptr text ,
short length )
{
long w1 , w2 , ce ;
TextMode ( srcBic ) ;
TextFace ( outline ) ;
w1 = TextWidth ( text , 0 , length ) ;
MoveTo ( x , y ) ;
DrawText ( text , 0 , length ) ;
TextMode ( srcOr ) ;
TextFace ( normal ) ;
w2 = TextWidth ( text , 0 , length ) ;
ce = ( w1 - w2 ) * 0x10000L / length ;
CharExtra ( ce ) ;
SpaceExtra ( ce ) ;
MoveTo ( x , y ) ;
DrawText ( text , 0 , length ) ;
CharExtra ( 0 ) ;
SpaceExtra ( 0 ) ;
}
It only works in color GrafPorts, but that’s to be expected since CharExtra
requires Color Quickdraw.
- Jon Wätte (h+@nada.kth.se)
Hagagatan 1, 113 48 Stockholm, Sweden
Auntie Flicker
Many operations, e specially moving and sizing of controls, cause a lot of flicker
on the screen. Some of this can be avoided by hiding the control, moving and sizing it,
and bringing it back, but even then there is more drawing to the screen than is really
necessary.
The trick to avoiding all this unnecessary drawing is to temporarily turn off
drawing during the operations which cause flicker, and then turn it on again. To do
this, simply replace the visRgn with a null region temporarily, i.e.:
/* 2 */
RgnHandle vis;
...
vis = window->visRgn;
window->visRgn = NewRgn();
... operations which would normally cause flicker ...
DisposeRgn( window->visRgn);
window->visRgn = vis;
... don’t forget to redraw or invalidate appropriately here!
- Jorg ‘jbx’ Brown
San Francisco, CA